package news.util;

import news.example.Publish;

import java.util.List;

/**
 * @author JiangJ
 * 分页对象
 * @date 2022/3/1 18:29
 */
public class PageBean {
    /**
     * 当前页码
     */
    private int currPageNo=1;
    /**
     * 页面大小，即每页显示记录数
     */
    private int pageSize=10;
    /**
     * 记录总数
     */
    private int totalCount=1;
    /**
     * 总页数-计算
     */
    private int totalPageCount=1;
    /**
     * 起始参数
     */
    private int start=0;
    /**
     * 页码
     */
    private int pageIndex=1;

    List<Publish> objectList;

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        initTotalPageCount();
        initStart();
    }

    /**
     * 初始化总页数
     */
    private void initTotalPageCount() {
        if (this.totalCount > 0) {
            //计算总页数
            this.totalPageCount = (this.totalCount % this.pageSize == 0) ?
                    (this.totalCount / pageSize) :
                    ((this.totalCount / pageSize) + 1);
        }

    }

    /**
     * 开始页数
     */
    private void initStart() {
        this.start = (this.currPageNo - 1) * this.pageSize;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public List<Publish> getObjectList() {
        return objectList;
    }
    /**
     * 集合对象
     */
    public void setObjectList(List<Publish> objectList) {
        this.objectList = objectList;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }
}
